<?php

$rootfolder = './';
$datafolder = $rootfolder . "upload";

set_time_limit(600);

if (!file_exists($datafolder)){
        echo "Datafolder doesn't exists: $datafolder<br>";
        exit(1);
}

if (!is_writable($datafolder)){
        echo "Datafolder not writable: $datafolder<br>";
        exit(1);
}

if (!$_SERVER['CONTENT_TYPE'] == "image/jpeg"){
        echo "Unsupported file format<br>";
        exit(1);
}

$putdata= file_get_contents("php://input");
if (strlen($putdata) == 0){
	$putdata= file_get_contents("php://stdin");
}
$name = "/img-" . time() . ".jpg";
$fullFileName = $datafolder . $name;
$fp = fopen($fullFileName, "w");
fwrite($fp, $putdata);
fclose($fp);

?>
